package collectionsDemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Demo3 {
	public static void main(String[] args){
		ArrayList<String> aList = new ArrayList<String>();
		aList.add("ccxxx");
		aList.add("bbcc");
		aList.add("kkk");
		aList.add("a");
		Collections.sort(aList);
		System.out.println(aList);
		
		//可以根据需求自己定义排序的规则，但是在Collection中要修改的是Comparator对象
		Collections.sort(aList, new ByLength());
		System.out.println(aList);
	}
}
class ByLength implements Comparator<String>{
	@Override
	public int compare(String str1, String str2) {
		// TODO Auto-generated method stub
		return -(str1.length()-str2.length());
	}
}







